import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Question20 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        in.nextLine();
        String[][] arrs = new String[n][3];

        for (int i = 0; i < n; i++) {
            String s = in.nextLine();
            arrs[i] = s.split(" ");
            // System.out.println(Arrays.toString(arrs[i]));
        }

        Arrays.sort(arrs, (String[] a, String[] b) -> {
            return Integer.valueOf(a[0]) - Integer.valueOf(b[0]);
        });

        int[] a = new int[n];
        int[] cnt = new int[n];
        char[] c = new char[n];
        int maxm = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Integer.valueOf(arrs[i][0]);
            cnt[i] = Integer.valueOf(arrs[i][1]);
            c[i] = arrs[i][2].charAt(0);

            maxm = Math.max(maxm, cnt[i]);
            // System.out.println(a[i] + " " + cnt[i] + " " + c[i]);
        }

        int ret = 0;

        for (char cc : new char[]{'S', 'H', 'D', 'C'}) {
            for (int t = 0; t < maxm; t++) {
                int last = -1;
                int count = 0;
                for (int i = 0; i < n; i++) {
                    if (c[i] == cc) {
                        if ((last == -1 || last == a[i] - 1) && cnt[i] > 0) {
                            last = a[i];
                            cnt[i]--;
                            count++;

                            if (count == 5) {
                                ret++;
                                count = 0;
                                last = -1;
                            }
                        }
                        else if (cnt[i] > 0){
                            last = a[i];
                            count = 1;
                        }
                        else {
                            last = -1;
                            count = 0;
                        }
                    }

                }
            }
        }

        System.out.println(ret);
    }
}